package cn.xuewenbao.ucenter.service.impl;

import cn.xuewenbao.ucenter.entity.MemberData;
import cn.xuewenbao.ucenter.entity.vo.FollowVo;
import cn.xuewenbao.ucenter.entity.vo.MemData;
import cn.xuewenbao.ucenter.mapper.MemberDataMapper;
import cn.xuewenbao.ucenter.service.FollowService;
import cn.xuewenbao.ucenter.service.MemberDataService;
import cn.xuewenbao.ucenter.service.MemberService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mafayu
 * @since 2021-04-06
 */
@Service
@Slf4j
public class MemberDataServiceImpl extends ServiceImpl<MemberDataMapper, MemberData> implements MemberDataService {

    @Override
    public Result<?> getMemberData(String memberId) {
        QueryWrapper<MemberData> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", memberId);
        MemberData memberData=baseMapper.selectOne(wrapper);
        Result<MemData> result = new Result<>();
        if (memberData == null) {
            result.setSuccess(false);
            result.setMessage("该用户的用户数据查询不到");
            return result;
        }
        MemData memData=new MemData();
        BeanUtils.copyProperties(memberData,memData);
        result.setSuccess(true);
        result.setResult(memData);
        return result;
    }

    @Override
    public Boolean addMemberData(String userId, Long likeCount, Long likedCount, Long favoriteCount, Long fanCount, Long followerCount) {
        MemberData data = new MemberData();
        data.setUserId(userId);
        data.setLikeCount(likeCount);
        data.setLikedCount(likedCount);
        data.setFavoriteCount(favoriteCount);
        data.setFanCount(fanCount);
        data.setFollowerCount(followerCount);
        int insert = baseMapper.insert(data);
        return insert > 0;
    }


}
